package com.chima.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.chima.domain.Department;
import com.chima.domain.HsCheckDepartment;

public class DepartmentDao extends HibernateDaoSupport{
	

	//分页查询
		public List<Department> findByCriteria(DetachedCriteria criteria, int firstResult,int maxResults) {
			return this.getHibernateTemplate().findByCriteria(criteria,firstResult,maxResults);
		}
	   //查找总页数
		public int findByTotalCount() {
			List list= this.getHibernateTemplate().find("select count(*) from Department");
			long temp = (Long) list.get(0);
			return (int) temp;
		}
		public void save(Department department) {
			this.getHibernateTemplate().save(department);
		}
		public void update(Department department) {
			this.getHibernateTemplate().update(department);
			
		}
		
		public void delete(int id) {
			this.getHibernateTemplate().delete(this.getHibernateTemplate().load(Department.class, id));
		}
		public Department findByName( String name) {
			Session session=this.getSession();
			Department d = (Department)session.createQuery("from Department d where d.name = ?").setParameter(0, name).uniqueResult();
			super.releaseSession(session);
			return d;
			
		}
		public Department findByIdAndflag(int id, int flag) {
			Session session=this.getSession();
			Department d = (Department)session.createQuery("from Department d where d.id = ? and d.flag=? ").setParameter(0,id).setParameter(1, flag).uniqueResult();
			super.releaseSession(session);
			return d;
			
		}
		public List<Department>  findByflag( int flag) {
			Session session=this.getSession();
			List<Department> d = (List<Department>)session.createQuery("from Department d where d.flag=? ").setParameter(0,flag).list();
			super.releaseSession(session);
			return d;
			
		}
		public Department  findById( int deptId) {
			Session session=this.getSession();
			Department d = (Department) session.createQuery("from Department d where d.id=? ").setParameter(0,deptId).uniqueResult();
			super.releaseSession(session);
			return d;
			
		}
		public List<Department>  findAll( ) {
			Session session=this.getSession();
			List<Department> d = (List<Department>)this.getSession().createQuery("from Department ").list();
			super.releaseSession(session);
			return d;
			
		}
		public List<HsCheckDepartment> findHsCheckDepartmentBymonth(
				String searchdate1) {
			Session session = super.getSession();
			List<HsCheckDepartment> d = session.createQuery("from HsCheckDepartment where monthdate=? " ).setParameter(0, searchdate1).list();
			super.releaseSession(session);
			return d;
		}
		public HsCheckDepartment findhsCheckDepartmentByid(int parseInt) {
			Session session = super.getSession();
			HsCheckDepartment d = (HsCheckDepartment) session.createQuery("from HsCheckDepartment where id=? " ).setParameter(0, parseInt).uniqueResult();
			super.releaseSession(session);
			return d;
		}
		public void addhsCheckDepartment(HsCheckDepartment hsCheckDepartment) {
			Session session = super.getSession();
			session.saveOrUpdate(hsCheckDepartment);
			super.releaseSession(session);
			
		}
		public List<Department> findListAllzhuyuanDepartment() {
			Session session=this.getSession();
			List<Department> d = (List<Department>)this.getSession().createQuery("from Department where xzorzy=1 ").list();
			super.releaseSession(session);
			return d;
		}
}
